package com.lijie.ljblog.config;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

//    @Value("${file.uploadurl}")
//    private String  fileUrl;

    @Bean
    public HandlerInterceptor initMyInterceptor(){
        return new MyInterceptor();
    }
    @Bean
    public HandlerInterceptor initUploadImgInterceptor(){
        return new UploadImgInterceptor();
    }


    /**
     * 注册拦截器
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor( initMyInterceptor())
                .addPathPatterns("/ljblog/Link/saveOrUpdate") //友联的新增
                .addPathPatterns("/ljblog/blog/saveOrUpdateBlog") //博客的发布
                .addPathPatterns("/ljblog/classify/addClassify") //博客的发布
                .addPathPatterns("/ljblog/Diary/saveOrUpdate") //博客的发布
                .addPathPatterns("/game/getGameSaveOrUpdate") //新增游戏
                .excludePathPatterns("/**/*.png", "/**/*.jpg","/**/*.jpeg", "/**/*.gif");
        registry.addInterceptor( initUploadImgInterceptor()).addPathPatterns("/ljblog/person/headerImg") //新增图片
                .addPathPatterns("/ljblog/person/headUpload") //新增图片
                .addPathPatterns("/common/imgUpload") //新增图片
                .excludePathPatterns("/**/*.png", "/**/*.jpg","/**/*.jpeg", "/**/*.gif");
    }



    public void addResourceHandlers(ResourceHandlerRegistry register){
        register.addResourceHandler("/images/**");
    }



}
